﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Common
{
    public static class NewtonsoftExtensions
    { 
        public static string SerializeObject(this object obj, string DateTimeFormat = "yyyy-MM-dd HH:mm:ss")
        { 
            return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings
            { 
                 DateFormatString=DateTimeFormat,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
        }

        public static T DeserializeObject<T>(this string data)
        {
            return JsonConvert.DeserializeObject<T>(data, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
        }
    }
}
